package com.example.springboot.jpa.service;

import com.example.springboot.jpa.dao.UserRepository;
import com.example.springboot.jpa.dao.UserRepository2;
import com.example.springboot.jpa.entity.User;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;

@Service
public class UserService {

	@Resource
	private UserRepository userRepository;
	@Resource
	private UserRepository2 userRepository2;

	// 保存
	@Transactional
	public void save(User user) {
		userRepository.save(user);
	}

	// 删除
	@Transactional
	public void delete(int id) {
		userRepository.delete(id);
	}

	// 查询
	public void getUser(int id) {
		userRepository.findOne(id);
	}

	// 根据名称查询
	public User findByUserName(String userName) {
		return userRepository2.findByUserName(userName);
	}

	// 根据名称查询
	public User findByUserName2(String userName) {
		return userRepository2.findByUserName2(userName);
	}

}
